package com.wms.model;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * @author This
 * @version 1.0
 * @className Customer
 * @description TODO
 * @date 2019/7/10 15:42
 */
public class Customer {
    private Integer id;
    private String cusName;
    private String cusPhone;
    private String cusAddr;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCusName() {
        return cusName;
    }

    public void setCusName(String cusName) {
        this.cusName = cusName;
    }

    public String getCusPhone() {
        return cusPhone;
    }

    public void setCusPhone(String cusPhone) {
        this.cusPhone = cusPhone;
    }

    public String getCusAddr() {
        return cusAddr;
    }

    public void setCusAddr(String cusAddr) {
        this.cusAddr = cusAddr;
    }

    public Map<String, String> getAttr(Customer customer) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("id", "id");
        map.put("cusName", "cus_name");
        map.put("cusPhone", "cus_phone");
        map.put("cusAddr", "cus_addr");
        Map<String, String> maps = new HashMap<String, String>();
        Set<String> keySet = map.keySet();
        try {
            // BeanUtil.populate map转bean
            // bean转化为map
            Map describe = BeanUtils.describe(customer);
            Set set = describe.keySet();
            for (Object o : set) {
                for (String s : keySet) {
                    if (describe.get(o).toString() != null && StringUtils.isNotEmpty(describe.get(o).toString()) && o.equals(s)) {
                        maps.put(map.get(s), describe.get(o).toString());
                    }
                }
            }
        } catch (Exception e) {
        }
        return maps;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "id=" + id +
                ", cusName='" + cusName + '\'' +
                ", cusPhone='" + cusPhone + '\'' +
                ", cusAddr='" + cusAddr + '\'' +
                '}';
    }
}
